package com.youlu.campus.web.data.english;

import com.youlu.campus.entity.VO.req.CheckMobileVO;
import com.youlu.campus.entity.VO.res.EnglishMobileReceiveRes;
import com.youlu.campus.service.english.MobileReceiveService;
import com.youlu.campus.service.utils.WebTokenUtils;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class MobileCaReceiveController {

    @Autowired
    private MobileReceiveService mobileReceiveService;

    @PostMapping("/public/mobile/receive")
    public QResult mobileCaReceiveLog(@RequestBody CheckMobileVO req, HttpServletRequest request) {
        req.setClientIp(request.getRemoteAddr());

        EnglishMobileReceiveRes mobileReceive = mobileReceiveService.login(req);
        if (StringUtils.isBlank(mobileReceive.getToken())) {
            mobileReceive.setToken(WebTokenUtils.signToken(mobileReceive.getOpenId()));
        }
        mobileReceive.setPlatform("wechat-h5");
        return QResult.success(mobileReceive);
    }
}
